﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Drawing;

namespace kasy_4
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //NotifyIcon ni = new NotifyIcon();
        Control control;

        public MainWindow()
        {
            InitializeComponent();            
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //ni.Text = "Kasy 4.0";
            //ni.Icon = new Icon("appicon.ico");
            //ni.Visible = true;
            //ni.Tag = "www.tatuum.com";           
            //ni.BalloonTipText = "Kan Sp. z o.o.";
            //ni.BalloonTipTitle = "Kasy 4.0";
            //ni.BalloonTipIcon = ToolTipIcon.Warning;
            //ni.DoubleClick +=new EventHandler(ni_DoubleClick);
            //ni.Click +=new EventHandler(ni_Click);
            //ni.ShowBalloonTip(10);
            
            control = new Control(this);
            control.Loaded();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            control.Logout();            
            //ni.Dispose();
        }

        private void ni_DoubleClick(object Sender, EventArgs e)
        {
            if (this.WindowState == WindowState.Minimized)
                this.WindowState = WindowState.Normal;
            this.Activate();
        }

        private void ni_Click(object Sender, EventArgs e)
        {
            
        }

        private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key.CompareTo(Key.F12) == 0)
            {
                try
                {
                    this.Close();                    
                }
                catch (Exception)
                {                    
                }
            }
            if (e.Key.CompareTo(Key.F8) == 0)
            {
                control.Logout();
            }
            if (e.Key.CompareTo(Key.F4) == 0)
            {
                control.CloseDocument();
            }
        }

        private void tbLogin_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key.CompareTo(Key.Enter)==0)
                this.pbPasswd.Focus();
        }

        private void pbPasswd_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key.CompareTo(Key.Enter) == 0)
            {
                control.Login(tbLogin.Text, pbPasswd.Password);
            }
        }

        private void btnNewBox_Click(object sender, RoutedEventArgs e)
        {
            control.NewBox();
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            control.CloseDocument();
        }

        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            control.CloseDocument();
        }

        private void tbScaner_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if(e.Key==Key.Enter)
                control.Scanner();
        }

        private void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            control.OpenDocument();
        }
               


    }
}
